#include "widget.h"
#include "ui_widget.h"

#include "showcamera.h"
#include "yolov8/yolov8.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // std::string model_path = "/home/cat/c_lib/rknn_model_zoo/examples/yolov8/model/people_v8_x.rknn";


    QString ip = "192.168.2.123";
    QString userName = "admin";
    QString password = "gq123456.";
    QString port = "554";

    QString rtspUrl = "rtsp://" + userName + ":" + password + "@" + ip + ":" +port + "/cam/realmonitor?channel=1&subtype=0&transport=tcp :network-caching=0";

    this->ca1 = new camera(rtspUrl);
    this->cameraThread1 = new QThread(this);
    this->ca1->moveToThread(this->cameraThread1);
    connect(this->ca1, &camera::frameReady,this->ui->showWidget1, &showcamera::setCameraData);
    connect(this->ca1,&camera::detectionsReady,this->ui->showWidget1,&showcamera::setDetections);
    connect(this->cameraThread1, &QThread::started, this->ca1, &camera::initCamera);

    this->ca2 = new camera(rtspUrl);
    this->cameraThread2 = new QThread(this);
    this->ca2->moveToThread(this->cameraThread2);
    connect(this->ca2, &camera::frameReady,this->ui->showWidget2, &showcamera::setCameraData);
    connect(this->ca2,&camera::detectionsReady,this->ui->showWidget2,&showcamera::setDetections);
    connect(this->cameraThread2, &QThread::started, this->ca2, &camera::initCamera);

    this->ca3 = new camera(rtspUrl);
    this->cameraThread3 = new QThread(this);
    this->ca3->moveToThread(this->cameraThread3);
    connect(this->ca3, &camera::frameReady,this->ui->showWidget3, &showcamera::setCameraData);
    connect(this->ca3,&camera::detectionsReady,this->ui->showWidget3,&showcamera::setDetections);
    connect(this->cameraThread3, &QThread::started, this->ca3, &camera::initCamera);

    this->ca4 = new camera(rtspUrl);
    this->cameraThread4 = new QThread(this);
    this->ca4->moveToThread(this->cameraThread4);
    connect(this->ca4, &camera::frameReady,this->ui->showWidget4, &showcamera::setCameraData);
    connect(this->ca4,&camera::detectionsReady,this->ui->showWidget4,&showcamera::setDetections);
    connect(this->cameraThread4, &QThread::started, this->ca4, &camera::initCamera);

    this->ca5 = new camera(rtspUrl);
    this->cameraThread5 = new QThread(this);
    this->ca5->moveToThread(this->cameraThread5);
    connect(this->ca5, &camera::frameReady,this->ui->showWidget5, &showcamera::setCameraData);
    connect(this->ca5,&camera::detectionsReady,this->ui->showWidget5,&showcamera::setDetections);
    connect(this->cameraThread5, &QThread::started, this->ca5, &camera::initCamera);

    this->ca6 = new camera(rtspUrl);
    this->cameraThread6 = new QThread(this);
    this->ca6->moveToThread(this->cameraThread6);
    connect(this->ca6, &camera::frameReady,this->ui->showWidget6, &showcamera::setCameraData);
    connect(this->ca6,&camera::detectionsReady,this->ui->showWidget6,&showcamera::setDetections);
    connect(this->cameraThread6, &QThread::started, this->ca6, &camera::initCamera);

    this->ca7 = new camera(rtspUrl);
    this->cameraThread7 = new QThread(this);
    this->ca7->moveToThread(this->cameraThread7);
    connect(this->ca7, &camera::frameReady,this->ui->showWidget7, &showcamera::setCameraData);
    connect(this->ca7,&camera::detectionsReady,this->ui->showWidget7,&showcamera::setDetections);
    connect(this->cameraThread7, &QThread::started, this->ca7, &camera::initCamera);

    this->ca8 = new camera(rtspUrl);
    this->cameraThread8 = new QThread(this);
    this->ca8->moveToThread(this->cameraThread8);
    connect(this->ca8, &camera::frameReady,this->ui->showWidget8, &showcamera::setCameraData);
    connect(this->ca8,&camera::detectionsReady,this->ui->showWidget8,&showcamera::setDetections);
    connect(this->cameraThread8, &QThread::started, this->ca8, &camera::initCamera);

    this->cameraThread1->start();
    this->cameraThread2->start();
    this->cameraThread3->start();
    this->cameraThread4->start();
    this->cameraThread5->start();
    this->cameraThread6->start();
    this->cameraThread7->start();
    this->cameraThread8->start();
}

Widget::~Widget()
{
    delete ui;
}
